﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WaterResources
{
    class WRFormula
    {
        /// <summary>
        /// 水环境计算公式
        /// </summary>
        /// <param name="C1">试验结束时上覆水水质C1 mg/L</param>
        /// <param name="C2">河道目标水质C2 mg/L</param>
        /// <param name="L1">取样点河道水深L1 m</param>
        /// <param name="L2">试验水柱高度L2 m</param>
        /// <returns></returns>
        public double EnvironmentFormula(double C1, double C2, double L1, double L2)
        {
            double x = ((C2 - C1) * L2) / L1 + C1;
            return Math.Round(x,3);
        }
        /// <summary>
        /// 水安全计算公式
        /// </summary>
        /// <param name="X">是否有边坡:1:X; X=0,h淤泥值：市：19cm,县：33cm,乡：47-61cm。为标准控制值</param>
        /// <param name="Y">市县乡：1,2,3</param>
        /// <param name="Z">实际输入的淤泥值：1,2,3</param>
        /// <param name="FloodWidth">河道宽度</param>
        /// <param name="floodHight">洪水高度</param>
        /// <param name="SecurityHight">安全超高值</param>
        /// <param name="Pobi">边坡比</param>
        /// <returns></returns>
        public string SecurityFormula(double X, string Y, double Z, double FloodWidth, double floodHight, double SecurityHight)
        {
            if (X == 0 && Y == "1")
            {
                if (Z <= 19)
                {
                    return "19&不需要清淤.";
                }
                else
                {
                    return "19&需要对该河道进行清淤.";
                }
            }
            else if (X == 0 && Y == "2")
            {
                if (Z <= 33)
                {
                    return "33&不需要清淤.";
                }
                else
                {
                    return "33&需要对该河道进行清淤.";
                }
            }
            else if (X == 0 && Y == "3")
            {
                if (Z <= 47)
                {
                    return "47&不需要清淤.";
                }
                else if (Z <= 61)
                {
                    return "61&建议对该河道进行清淤.";
                }
                else
                {
                    return "61&需要对该河道进行清淤.";
                }
            }
            var Pobi = 1 / X;
            double t = Math.Sqrt((0.04 / X) * NotSilt(FloodWidth, floodHight, SecurityHight, X) + Math.Pow(BottomWidth(FloodWidth, floodHight, SecurityHight, X), 2) / 4 * Math.Pow(Pobi, 2)) - BottomWidth(FloodWidth, floodHight, SecurityHight, X) / 2 * Pobi;
            var tt = Math.Round(t, 3);
            if (X != 0 && Y == "1")
            {
                if (Z <= tt)
                {
                    return ""+tt+"&不需要清淤.";
                }
                else
                {
                    return "" + tt + "&需要对该河道进行清淤.";
                }
            }
            else if (X != 0 && Y == "2")
            {
                if (Z <= tt)
                {
                    return "" + tt + "&不需要清淤.";
                }
                else
                {
                    return "" + tt + "&需要对该河道进行清淤.";
                }
            }
            else if (X != 0 && Y == "3")
            {
                if (Z <= tt)
                {
                    return "" + tt + "&不需要清淤.";
                }
                else
                {
                    return "" + tt + "&需要对该河道进行清淤.";
                }
            }
            else
            {
                return "0&请检查录入的值是否正确！系统未计算出结果！";
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="FloodWidth">河道宽度</param>
        /// <param name="floodHight">洪水高度</param>
        /// <param name="SecurityHight">安全超高值</param>
        /// <param name="Pobi">边坡比</param>
        /// Smax-河道最大过水断面面积
        /// <returns></returns>
        public double NotSilt(double FloodWidth, double floodHight, double SecurityHight, double Pobi)
        {
            double L = BottomWidth(FloodWidth, floodHight, SecurityHight, Pobi);
            double Smax = Math.Pow(floodHight + SecurityHight, 2) * Pobi + L * (floodHight + SecurityHight);
            return Smax;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="SiltH">泥沙淤积厚度</param>
        /// <param name="Pobi">边坡比</param>
        /// <param name="FloodWidth">河底宽度</param>
        /// <param name="floodHight">洪水高度</param>
        /// <param name="SecurityHight">安全超高值</param>
        /// <returns></returns>
        public double YesSilt(double SiltH, double Pobi, double FloodWidth, double floodHight, double SecurityHight)
        {
            double L = BottomWidth(FloodWidth, floodHight, SecurityHight, Pobi);
            double Smax = Math.Pow(SiltH, 2) * Pobi + SiltH * L;
            return Smax;
        }
        /// <summary>
        /// 河槽宽度计算
        /// </summary>
        /// <param name="L1"></param>
        /// <param name="H1"></param>
        /// <param name="H2"></param>
        /// <param name="X"></param>
        /// <returns></returns>
        public double BottomWidth(double L1, double H1, double H2, double X)
        {
            if (X==0) {
                return L1;
            }
            double L = L1 - 2 * (H1 + H2) * 1/X;
            return L;
        }
    }
}
